﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InformaticaDiary.InformaticaDiaryDAL;
using System.Configuration;
using InformaticaDiaryWeb;
using InformaticaDiary.Common;

namespace InformaticaDiaryWeb.Service
{
    public class DataAccess : IDataAccess
    {
        IDataAccess objDataAccess;
        
        public DataAccess()
        {
            if (ConfigurationManager.AppSettings["DatabaseType"] == "MsAccess")
            {
                string path = WebConfiguration.ServerAccessMdbPath;
                string str = "Provider=MSDASQL.1;Password=admin;Persist Security Info=True;User ID=admin;DBQ=" + path + ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes";
                objDataAccess = new DataAccessOdbc(str);
            }
            else if (ConfigurationManager.AppSettings["DatabaseType"] == "MsSQL")
            {
                string str = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
                objDataAccess = new DataAccessSql(str);
            }            
        }

        public InformaticaDiary.Common.ExecutedResult Delete(long Id)
        {
            return objDataAccess.Delete(Id);
        }      

        public long Maxid(string strprint)
        {
            return objDataAccess.Maxid(strprint);
        }

        public long Maxid1()
        {
            return objDataAccess.Maxid1();
        }

        public long Maxid2()
        {
            return objDataAccess.Maxid2();
        }

        public InformaticaDiary.Common.ExecutedResult Insert(long Id, InformaticaDiary.Common.CaseDetails objCD)
        {
            return objDataAccess.Insert(Id, objCD);
        }

        public InformaticaDiary.Common.ExecutedResult Update(long Id, InformaticaDiary.Common.CaseDetails objCD)
        {
            return objDataAccess.Update(Id, objCD);
        }
        public InformaticaDiary.Common.ExecutedResult Login(InformaticaDiary.Common.LoginRequest objLoginRequest)
        {
            return objDataAccess.Login(objLoginRequest);
        }


        public List<SearchResult> DoSearch(InformaticaDiary.Common.SearchValue objSearchValue)
        {
            return objDataAccess.DoSearch(objSearchValue);
        }


        public List<CaseType> GetCaseType(long casetypeid = 0)
        {
            return objDataAccess.GetCaseType(casetypeid);
        }

        public List<int> GetYear()
        {
            return objDataAccess.GetYear();
        }


        public CaseDetails GetCaseDetails(long CaseDetailsID)
        {
            return objDataAccess.GetCaseDetails(CaseDetailsID);
        }
    }
}